﻿using System;
using System.Threading;
using System.Windows.Controls;
using System.Windows.Threading;


namespace ITSSP.Controls.ExtensionMethods
{
	public static class ChildWindowExtensions
	{
		public delegate void HandlerDelegate(Object sender, EventArgs e);
		public static void ShowDialog(this ChildWindow window)
		{
			System.Threading.AutoResetEvent waitHandle = new System.Threading.AutoResetEvent(false);
			window.Dispatcher.BeginInvoke(() =>
			{
				window.Closed += (s, e) => waitHandle.Set();
				window.Show();
			});
			waitHandle.WaitOne();
		}

		public static void Show(this ChildWindow window, HandlerDelegate handler)
		{
			window.Closed +=  new EventHandler(handler);
			window.Show();
		}
	}
}
